package c.e.a.b.f.b;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class m3 extends a5 {
    public final p3 c = new p3(this, this.a.a, "google_app_measurement_local.db");
    public boolean d;

    public m3(u4 u4Var) {
        super(u4Var);
    }

    public static long w(SQLiteDatabase sQLiteDatabase) {
        Cursor cursor = null;
        try {
            cursor = sQLiteDatabase.query("messages", new String[]{"rowid"}, "type=?", new String[]{"3"}, null, null, "rowid desc", "1");
            if (cursor.moveToFirst()) {
                long j = cursor.getLong(0);
                cursor.close();
                return j;
            }
            cursor.close();
            return -1;
        } catch (Throwable th) {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    public final SQLiteDatabase A() throws SQLiteException {
        if (this.d) {
            return null;
        }
        SQLiteDatabase writableDatabase = this.c.getWritableDatabase();
        if (writableDatabase != null) {
            return writableDatabase;
        }
        this.d = true;
        return null;
    }

    public final boolean v() {
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:81:0x011c  */
    /* JADX WARNING: Removed duplicated region for block: B:83:0x0121  */
    /* JADX WARNING: Removed duplicated region for block: B:81:0x011c  */
    /* JADX WARNING: Removed duplicated region for block: B:83:0x0121  */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x010c  */
    /* JADX WARNING: Removed duplicated region for block: B:95:0x0114 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x0111  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x00f1  */
    /* JADX WARNING: Removed duplicated region for block: B:93:0x0114 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x00f6  */
    /* JADX WARNING: Removed duplicated region for block: B:49:0x00c2 A:{SYNTHETIC, Splitter:B:49:0x00c2} */
    /* JADX WARNING: Removed duplicated region for block: B:55:0x00db  */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x0114 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x00e0  */
    /* JADX WARNING: Removed duplicated region for block: B:81:0x011c  */
    /* JADX WARNING: Removed duplicated region for block: B:83:0x0121  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x00f1  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x00f6  */
    /* JADX WARNING: Removed duplicated region for block: B:93:0x0114 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:49:0x00c2 A:{SYNTHETIC, Splitter:B:49:0x00c2} */
    /* JADX WARNING: Removed duplicated region for block: B:55:0x00db  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x00e0  */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x0114 A:{SYNTHETIC} */
    public final boolean x(int r17, byte[] r18) {
        /*
        r16 = this;
        r1 = r16;
        r16.g();
        r0 = r1.d;
        r2 = 0;
        if (r0 == 0) goto L_0x000b;
    L_0x000a:
        return r2;
    L_0x000b:
        r3 = new android.content.ContentValues;
        r3.<init>();
        r0 = java.lang.Integer.valueOf(r17);
        r4 = "type";
        r3.put(r4, r0);
        r0 = "entry";
        r4 = r18;
        r3.put(r0, r4);
        r4 = 5;
        r5 = 0;
        r6 = 5;
    L_0x0023:
        if (r5 >= r4) goto L_0x0125;
    L_0x0025:
        r7 = 0;
        r8 = 1;
        r9 = r16.A();	 Catch:{ SQLiteFullException -> 0x00fa, SQLiteDatabaseLockedException -> 0x00e8, SQLiteException -> 0x00be, all -> 0x00bb }
        if (r9 != 0) goto L_0x0035;
    L_0x002d:
        r1.d = r8;	 Catch:{ SQLiteFullException -> 0x00b9, SQLiteDatabaseLockedException -> 0x00e9, SQLiteException -> 0x00b5 }
        if (r9 == 0) goto L_0x0034;
    L_0x0031:
        r9.close();
    L_0x0034:
        return r2;
    L_0x0035:
        r9.beginTransaction();	 Catch:{ SQLiteFullException -> 0x00b9, SQLiteDatabaseLockedException -> 0x00e9, SQLiteException -> 0x00b5 }
        r10 = 0;
        r0 = "select count(1) from messages";
        r12 = r9.rawQuery(r0, r7);	 Catch:{ SQLiteFullException -> 0x00b9, SQLiteDatabaseLockedException -> 0x00e9, SQLiteException -> 0x00b5 }
        if (r12 == 0) goto L_0x0053;
    L_0x0042:
        r0 = r12.moveToFirst();	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        if (r0 == 0) goto L_0x0053;
    L_0x0048:
        r10 = r12.getLong(r2);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        goto L_0x0053;
    L_0x004d:
        r0 = move-exception;
        goto L_0x00a9;
    L_0x004f:
        r0 = move-exception;
        goto L_0x00ac;
    L_0x0051:
        r0 = move-exception;
        goto L_0x00b0;
    L_0x0053:
        r0 = "messages";
        r13 = 100000; // 0x186a0 float:1.4013E-40 double:4.94066E-319;
        r15 = (r10 > r13 ? 1 : (r10 == r13 ? 0 : -1));
        if (r15 < 0) goto L_0x0096;
    L_0x005c:
        r15 = r16.d();	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r15 = r15.f;	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r4 = "Data loss, local db full";
        r15.a(r4);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r13 = r13 - r10;
        r10 = 1;
        r13 = r13 + r10;
        r4 = "rowid in (select rowid from messages order by rowid asc limit ?)";
        r10 = new java.lang.String[r8];	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r11 = java.lang.Long.toString(r13);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r10[r2] = r11;	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r4 = r9.delete(r0, r4, r10);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r10 = (long) r4;	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r4 = (r10 > r13 ? 1 : (r10 == r13 ? 0 : -1));
        if (r4 == 0) goto L_0x0096;
    L_0x007e:
        r4 = r16.d();	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r4 = r4.f;	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r15 = "Different delete count than expected in local db. expected, received, difference";
        r2 = java.lang.Long.valueOf(r13);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r8 = java.lang.Long.valueOf(r10);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r13 = r13 - r10;
        r10 = java.lang.Long.valueOf(r13);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r4.d(r15, r2, r8, r10);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
    L_0x0096:
        r9.insertOrThrow(r0, r7, r3);	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r9.setTransactionSuccessful();	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        r9.endTransaction();	 Catch:{ SQLiteFullException -> 0x0051, SQLiteDatabaseLockedException -> 0x00ae, SQLiteException -> 0x004f, all -> 0x004d }
        if (r12 == 0) goto L_0x00a4;
    L_0x00a1:
        r12.close();
    L_0x00a4:
        r9.close();
        r2 = 1;
        return r2;
    L_0x00a9:
        r7 = r12;
        goto L_0x011a;
    L_0x00ac:
        r7 = r12;
        goto L_0x00b6;
    L_0x00ae:
        r7 = r12;
        goto L_0x00e9;
    L_0x00b0:
        r7 = r12;
        goto L_0x00fc;
    L_0x00b2:
        r0 = move-exception;
        goto L_0x011a;
    L_0x00b5:
        r0 = move-exception;
    L_0x00b6:
        r2 = r7;
        r7 = r9;
        goto L_0x00c0;
    L_0x00b9:
        r0 = move-exception;
        goto L_0x00fc;
    L_0x00bb:
        r0 = move-exception;
        r9 = r7;
        goto L_0x011a;
    L_0x00be:
        r0 = move-exception;
        r2 = r7;
    L_0x00c0:
        if (r7 == 0) goto L_0x00cb;
    L_0x00c2:
        r4 = r7.inTransaction();	 Catch:{ all -> 0x00e4 }
        if (r4 == 0) goto L_0x00cb;
    L_0x00c8:
        r7.endTransaction();	 Catch:{ all -> 0x00e4 }
    L_0x00cb:
        r4 = r16.d();	 Catch:{ all -> 0x00e4 }
        r4 = r4.f;	 Catch:{ all -> 0x00e4 }
        r8 = "Error writing entry to local database";
        r4.b(r8, r0);	 Catch:{ all -> 0x00e4 }
        r4 = 1;
        r1.d = r4;	 Catch:{ all -> 0x00e4 }
        if (r2 == 0) goto L_0x00de;
    L_0x00db:
        r2.close();
    L_0x00de:
        if (r7 == 0) goto L_0x0114;
    L_0x00e0:
        r7.close();
        goto L_0x0114;
    L_0x00e4:
        r0 = move-exception;
        r9 = r7;
        r7 = r2;
        goto L_0x011a;
    L_0x00e8:
        r9 = r7;
    L_0x00e9:
        r10 = (long) r6;
        android.os.SystemClock.sleep(r10);	 Catch:{ all -> 0x00b2 }
        r6 = r6 + 20;
        if (r7 == 0) goto L_0x00f4;
    L_0x00f1:
        r7.close();
    L_0x00f4:
        if (r9 == 0) goto L_0x0114;
    L_0x00f6:
        r9.close();
        goto L_0x0114;
    L_0x00fa:
        r0 = move-exception;
        r9 = r7;
    L_0x00fc:
        r2 = r16.d();	 Catch:{ all -> 0x00b2 }
        r2 = r2.f;	 Catch:{ all -> 0x00b2 }
        r4 = "Error writing entry; local database full";
        r2.b(r4, r0);	 Catch:{ all -> 0x00b2 }
        r2 = 1;
        r1.d = r2;	 Catch:{ all -> 0x00b2 }
        if (r7 == 0) goto L_0x010f;
    L_0x010c:
        r7.close();
    L_0x010f:
        if (r9 == 0) goto L_0x0114;
    L_0x0111:
        r9.close();
    L_0x0114:
        r5 = r5 + 1;
        r2 = 0;
        r4 = 5;
        goto L_0x0023;
    L_0x011a:
        if (r7 == 0) goto L_0x011f;
    L_0x011c:
        r7.close();
    L_0x011f:
        if (r9 == 0) goto L_0x0124;
    L_0x0121:
        r9.close();
    L_0x0124:
        throw r0;
    L_0x0125:
        r0 = r16.d();
        r0 = r0.n;
        r2 = "Failed to write entry to local database";
        r0.a(r2);
        r2 = 0;
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.m3.x(int, byte[]):boolean");
    }

    public final void y() {
        g();
        try {
            int delete = A().delete("messages", null, null) + 0;
            if (delete > 0) {
                d().n.b("Reset local analytics data. records", Integer.valueOf(delete));
            }
        } catch (SQLiteException e) {
            d().f.b("Error resetting local analytics data. error", e);
        }
    }

    /* JADX WARNING: Missing block: B:42:0x008a, code skipped:
            r3 = r3 + 1;
     */
    public final boolean z() {
        /*
        r11 = this;
        r0 = "Error deleting app launch break from local database";
        r11.g();
        r1 = r11.d;
        r2 = 0;
        if (r1 == 0) goto L_0x000b;
    L_0x000a:
        return r2;
    L_0x000b:
        r1 = r11.a;
        r1 = r1.a;
        r3 = "google_app_measurement_local.db";
        r1 = r1.getDatabasePath(r3);
        r1 = r1.exists();
        if (r1 != 0) goto L_0x001c;
    L_0x001b:
        return r2;
    L_0x001c:
        r1 = 5;
        r3 = 0;
        r4 = 5;
    L_0x001f:
        if (r3 >= r1) goto L_0x0093;
    L_0x0021:
        r5 = 0;
        r6 = 1;
        r5 = r11.A();	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        if (r5 != 0) goto L_0x0031;
    L_0x0029:
        r11.d = r6;	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        if (r5 == 0) goto L_0x0030;
    L_0x002d:
        r5.close();
    L_0x0030:
        return r2;
    L_0x0031:
        r5.beginTransaction();	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r7 = "messages";
        r8 = "type == ?";
        r9 = new java.lang.String[r6];	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r10 = 3;
        r10 = java.lang.Integer.toString(r10);	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r9[r2] = r10;	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r5.delete(r7, r8, r9);	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r5.setTransactionSuccessful();	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r5.endTransaction();	 Catch:{ SQLiteFullException -> 0x0079, SQLiteDatabaseLockedException -> 0x006d, SQLiteException -> 0x0050 }
        r5.close();
        return r6;
    L_0x004e:
        r0 = move-exception;
        goto L_0x008d;
    L_0x0050:
        r7 = move-exception;
        if (r5 == 0) goto L_0x005c;
    L_0x0053:
        r8 = r5.inTransaction();	 Catch:{ all -> 0x004e }
        if (r8 == 0) goto L_0x005c;
    L_0x0059:
        r5.endTransaction();	 Catch:{ all -> 0x004e }
    L_0x005c:
        r8 = r11.d();	 Catch:{ all -> 0x004e }
        r8 = r8.f;	 Catch:{ all -> 0x004e }
        r8.b(r0, r7);	 Catch:{ all -> 0x004e }
        r11.d = r6;	 Catch:{ all -> 0x004e }
        if (r5 == 0) goto L_0x008a;
    L_0x0069:
        r5.close();
        goto L_0x008a;
    L_0x006d:
        r6 = (long) r4;
        android.os.SystemClock.sleep(r6);	 Catch:{ all -> 0x004e }
        r4 = r4 + 20;
        if (r5 == 0) goto L_0x008a;
    L_0x0075:
        r5.close();
        goto L_0x008a;
    L_0x0079:
        r7 = move-exception;
        r8 = r11.d();	 Catch:{ all -> 0x004e }
        r8 = r8.f;	 Catch:{ all -> 0x004e }
        r8.b(r0, r7);	 Catch:{ all -> 0x004e }
        r11.d = r6;	 Catch:{ all -> 0x004e }
        if (r5 == 0) goto L_0x008a;
    L_0x0087:
        r5.close();
    L_0x008a:
        r3 = r3 + 1;
        goto L_0x001f;
    L_0x008d:
        if (r5 == 0) goto L_0x0092;
    L_0x008f:
        r5.close();
    L_0x0092:
        throw r0;
    L_0x0093:
        r0 = r11.d();
        r0 = r0.i;
        r1 = "Error deleting app launch break from local database in reasonable time";
        r0.a(r1);
        return r2;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.m3.z():boolean");
    }
}
